#pragma once

#include<BWAPI.h>
using namespace BWAPI;

#define _USE_MATH_DEFINES
#include<math.h>

bool TurnTowardAngle(float& angleNow , const float& target , const float& offset) //true for arrival
{
	float otherSide = target - M_PI;
	const float M_2PI = M_PI * 2.0f;
	if(otherSide < 0.0f)
	{
		otherSide += M_2PI;
	}

	if(target < M_PI)
	{
		if(angleNow < target || angleNow > otherSide)
		{
			angleNow += offset;
			if(angleNow > M_2PI)
			{
				angleNow -= M_2PI;
			}
			if(angleNow < target || angleNow > otherSide)
			{
				return false;
			}
			else
			{
				angleNow = target;
				return true;
			}
		}
		else
		{
			angleNow -= offset;
			if(angleNow < 0.0f)
			{
				angleNow += M_2PI;
			}
			if(angleNow < target || angleNow > otherSide)
			{
				angleNow = target;
				return true;
			}
			else
			{
				return false;
			}
		}
	}
	else
	{
		if(angleNow < target && angleNow > otherSide)
		{
			angleNow += offset;
			if(angleNow > M_2PI)
			{
				angleNow -= M_2PI;
			}
			if(angleNow < target && angleNow > otherSide)
			{
				return false;
			}
			else
			{
				angleNow = target;
				return true;
			}
		}
		else
		{
			angleNow -= offset;
			if(angleNow < 0.0f)
			{
				angleNow += M_2PI;
			}
			if(angleNow < target && angleNow > otherSide)
			{
				angleNow = target;
				return true;
			}
			else
			{
				return false;
			}
		}
	}
}